/**
 * @file bsp_uart.h
 * @brief UART driver for H743-V2 Flight Control System
 * @author Flight Control Team
 * @date 2025-10-31
 */

#ifndef __BSP_UART_H
#define __BSP_UART_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>

/**
 * @brief UART port identifiers
 */
typedef enum {
    UART_PORT_DEBUG = 0,    // USART6 - PC6/PC7
    UART_PORT_GPS1,         // USART2 - PA2/PA3
    UART_PORT_GPS2,         // USART3 - PD8/PD9
    UART_PORT_TELEM1,       // UART4 - PA0/PA1
    UART_PORT_TELEM2,       // UART5 - PB6/PB5
    UART_PORT_TELEM3,       // UART7 - PE8/PE7
    UART_PORT_TELEM4,       // UART8 - PE1/PE0
    UART_PORT_RC,           // USART1 - PA9/PA10
    UART_PORT_COUNT
} UARTPort_t;

/**
 * @brief UART configuration
 */
typedef struct {
    uint32_t baudrate;
    uint8_t data_bits;
    uint8_t stop_bits;
    uint8_t parity;
    bool flow_control;
} UARTConfig_t;

/**
 * @brief Initialize UART
 * @return 0 on success, -1 on error
 */
int BSP_UART_Init(void);

/**
 * @brief Configure UART port
 * @param port UART port
 * @param config UART configuration
 * @return 0 on success, -1 on error
 */
int BSP_UART_Configure(UARTPort_t port, const UARTConfig_t *config);

/**
 * @brief Send data via UART
 * @param port UART port
 * @param data Pointer to data
 * @param len Data length
 * @return Number of bytes sent
 */
int BSP_UART_Send(UARTPort_t port, const uint8_t *data, uint16_t len);

/**
 * @brief Receive data from UART
 * @param port UART port
 * @param data Pointer to buffer
 * @param len Maximum length
 * @return Number of bytes received
 */
int BSP_UART_Receive(UARTPort_t port, uint8_t *data, uint16_t len);

#ifdef __cplusplus
}
#endif

#endif /* __BSP_UART_H */

